package com.yellowpage.wf.service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;
import com.yellowpage.wf.dao.ContextDao;
import com.yellowpage.wf.data.Context;

public class ContextServiceImpl extends BaseServiceImpl implements ContextService {
	  private ContextDao workflowContextDao;
	
	  public void setContextDao(ContextDao workflowContextDao) {
		  this.workflowContextDao = workflowContextDao;
	  }
	
	
	  /* White generate Method */ 
	  public Context getContext(Long id){
	      return workflowContextDao.get(id);
	  }
	  
    public List<Context> getAllContext(){
        return workflowContextDao.getAll();
    }
    
    public List<Map> queryContextByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.CONTEXT_ID , a.PARAM_NAME , a.PARAM_TYPE, a.DEFAULT_VALUE  FROM WF_CONTEXT a WHERE 1=1 ")
				    			   			.addCondition(" and PARAM_NAME = :paramName ")
							    			.addCondition(" and WORKFLOW_ID = :workflowId ")
							    ; 	

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveContext(Context workflowContext){
        workflowContextDao.save(workflowContext);
    }
	  public void updateContext(Context workflowContext){
	      workflowContextDao.update(workflowContext);
	  }
	  
	  public void delete(List deleteList){
	      workflowContextDao.remove(deleteList);
	  }
	
	
	public Context getContext(String paramName , String paramValue) {
		List<Context> list = this.baseDao.getObjectListByConditions("from Context w where w.paramName = ? and w.paramValue = ? ", new Object[]{paramName,paramValue});
		
		
		
		return list.size() > 0 ? list.get(0) : null;
	}
	 
	
}	